﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.ComponentModel;
using System.IO;
using System.Reflection;

namespace WoodRobotics.Weather.ModelView
{
    
    public class AstronomyEvent : INotifyPropertyChanged
    {

        #region Fields
        private EventType m_Type;
        #endregion
        
        #region Properties
        public BitmapImage Image
        {
            get { return ImageFromEventType(Type); }
        }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public string Description { get; set; }
        public EventType Type
        {
            get { return m_Type; }
            set
            {
                m_Type = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Image"));
            }
        }
        #endregion
        
        #region Methods
        private BitmapImage ImageFromEventType(EventType Type)
        {

            string l_TypeURI = "WoodRobotics.Weather.Images.astronomy.astrocal";

            Stream l_ImgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(l_TypeURI + string.Format("{0:00}", ((int)Type) + 1) + ".gif");
            byte[] l_GifBits = new byte[l_ImgStream.Length];
            l_ImgStream.Read(l_GifBits, 0, l_GifBits.Length);
            l_ImgStream.Close();

            return GetBitmapImage(l_GifBits);
            
        }
        private BitmapImage GetBitmapImage(byte[] imageBytes)
        {
            var bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = new MemoryStream(imageBytes);
            bitmapImage.EndInit();
            return bitmapImage;
        }
        #endregion

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion
        
    }

    #region Enum
    public enum EventType
    {
        NewMoon,
        FullMoon,
        LunarEcipse,
        SolarEclipse,
        PlanetaryEvent,
        Conjunction,
        Occultation,
        SolarEvent,
        MeteorShower,
        Comet,
        Asteroid,
        AstronomyEvent,
        SpacecraftEvent
    }
    #endregion

}